package com.lsh.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Cookie工具类，传递一个 request对象和 cookie的key，返回此cookie的value
 */
public class CookieUtil {
    public static String getCookieValue(HttpServletRequest request,String cookieName){
        if (request == null || cookieName == null) {
            throw new IllegalArgumentException("参数为空!");
        }
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if(cookie.getName().equals(cookieName)){
                return cookie.getValue();
            }
        }
        return null;
    }
}
